using System;
using System.Collections.Generic;
using System.Text;

namespace ADEVSO.Data.SqlClient
{
    public static class Common
    {
        /// <summary>
        /// Get .Net Data Type from Sql Data Type
        /// </summary>
        /// <param name="SqlDataType"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public static Object GetDataType(String SqlDataType, Object Value)
        {
            Object result = null;
            switch (SqlDataType)
            {
                case "bigint": { result = Convert.ToInt64(Value.ToString()); break; }
                case "char": { result = Value.ToString(); break; }
                case "datetime": { result = Convert.ToDateTime(Value.ToString()); break; }
                case "decimal": { result = Convert.ToDecimal(Value.ToString()); break; }
                case "float": { result = float.Parse(Value.ToString()); break; }
                case "int": { result = Convert.ToInt32(Value.ToString()); break; }
                case "text": { result = Value.ToString(); break; }
                case "varchar": { result = Value.ToString(); break; }
                case "image": { result = ((byte[])Value); break; }
                case "nchar": { result = Convert.ToInt32(Value.ToString()); break; }
            }
            return result;
        }

        /// <summary>
        /// Get .Net Data Type Name from Sql Data Type
        /// </summary>
        /// <param name="SqlDataType"></param>
        /// <returns></returns>
        public static String GetDataTypeName(String SqlDataType)
        {
            String result = null;
            switch (SqlDataType)
            {
                case "bigint": { result = "Int64"; break; }
                case "char": { result = "String"; break; }
                case "datetime": { result = "DateTime"; break; }
                case "decimal": { result = "Decimal"; break; }
                case "float": { result = "float"; break; }
                case "int": { result = "Int32"; break; }
                case "text": { result = "String"; break; }
                case "varchar": { result = "String"; break; }
                case "image": { result = "byte[]"; break; }
                case "nchar": { result = "String"; break; }
            }
            return result;
        }
    }
}
